#include <iostream>
using namespace std;
const int maxn = 35;
struct Node
{
    Node *lchild, *rchild;
    int key;
};
int po[maxn], io[maxn];
void createTree(Node *&t, int ps, int pe, int is, int ie)
{
    if (ps > pe || is > ie)
        return;
    else
    {
        t = new Node();
        t->key = po[pe];
        for (int i = is; i <= ie; i++)
            if (io[i] == t->key)
            {
                createTree(t->lchild, ps, ps + i - is - 1, is, i - 1);
                createTree(t->rchild, ps + i - is, pe - 1, i + 1, ie);
                break;
            }
    }
}
void levelorder(Node *t)
{
    Node *queue[maxn];
    int front = 0, rear = 0, first = 1;
    if (t != NULL)
    {
        queue[rear] = t;
        rear = (rear + 1) % maxn;
        while (front != rear)
        {
            if (first)
            {
                cout << queue[front]->key;
                first = 0;
            }
            else
            {
                cout << " " << queue[front]->key;
            }

            if (queue[front]->lchild != NULL)
            {
                queue[rear] = queue[front]->lchild;
                rear = (rear + 1) % maxn;
            }
            if (queue[front]->rchild != NULL)
            {
                queue[rear] = queue[front]->rchild;
                rear = (rear + 1) % maxn;
            }
            front = (front + 1) % maxn;
        }
    }
}
int main()
{
    int n, i;
    cin >> n;
    for (i = 1; i <= n; i++)
    {
        cin >> po[i];
    }
    for (i = 1; i <= n; i++)
    {
        cin >> io[i];
    }
    Node *tree;
    createTree(tree, 1, n, 1, n);
    levelorder(tree);
    return 0;
}